home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / mweb / MWEB Utils / ws295sdk.exe / Ws2sdkzp.exe / SAMPLES / LAYERED / DLLMAIN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-06  |  2.4 KB  |  90 lines

  1. /*++
  2.  
  3.      Copyright (c) 1996 Intel Corporation
  4.      Copyright (c) 1996 Microsoft Corporation
  5.      All Rights Reserved
  6.  
  7.      Permission is granted to use, copy and distribute this software and
  8.      its documentation for any purpose and without fee, provided, that
  9.      the above copyright notice and this statement appear in all copies.
  10.      Intel makes no representations about the suitability of this
  11.      software for any purpose.  This software is provided "AS IS."
  12.  
  13.      Intel specifically disclaims all warranties, express or implied,
  14.      and all liability, including consequential and other indirect
  15.      damages, for the use of this software, including liability for
  16.      infringement of any proprietary rights, and including the
  17.      warranties of merchantability and fitness for a particular purpose.
  18.      Intel does not assume any responsibility for any errors which may
  19.      appear in this software nor any responsibility to update it.
  20.  
  21.  
  22. Module Name:
  23.  
  24.     dllmain.cpp
  25.  
  26. Abstract:
  27.     This module contains the DllMain entry point for lsp.dll to
  28.     control the global init and shutdown of the DLL.
  29.  
  30. --*/
  31.  
  32. #pragma warning(disable: 4001)      /* Single-line comment */
  33.  
  34. #include "precomp.h"
  35.  
  36. HINSTANCE   HDllInstance;
  37. DWORD       TlsIndex=0xFFFFFFFF;
  38.  
  39.  
  40. BOOL WINAPI DllMain(
  41.     IN HINSTANCE hinstDll,
  42.     IN DWORD fdwReason,
  43.     LPVOID lpvReserved
  44.     )
  45. {
  46.  
  47.    switch (fdwReason) {
  48.  
  49.    case DLL_PROCESS_ATTACH:
  50.       // DLL is attaching to the address
  51.       // space of the current process.
  52.       DTHookInitialize();
  53.       InitializeCriticalSection(&gInitCriticalSection);
  54.       HDllInstance = hinstDll;
  55.       TlsIndex = TlsAlloc();
  56.       break;
  57.  
  58.    case DLL_THREAD_ATTACH:
  59.       // A new thread is being created in the current process.
  60.       break;
  61.  
  62.    case DLL_THREAD_DETACH:
  63.       // A thread is exiting cleanly.
  64.       break;
  65.  
  66.    case DLL_PROCESS_DETACH:
  67.       // The calling process is detaching
  68.       // the DLL from its address space.
  69.       //
  70.       // Note that lpvReserved will be NULL if the detach is due to
  71.       // a FreeLibrary() call, and non-NULL if the detach is due to
  72.       // process cleanup.
  73.       //
  74.  
  75.       if( lpvReserved == NULL ) {
  76.           if (TlsIndex!=0xFFFFFFFF) {
  77.               TlsFree (TlsIndex);
  78.               TlsIndex = 0xFFFFFFFF;
  79.           }
  80.       }
  81.  
  82.       DeleteCriticalSection(&gInitCriticalSection);
  83.       DTHookShutdown();
  84.       break;
  85.    }
  86.  
  87.  
  88.    return(TRUE);
  89. }
  90.